package com.luoc.base.wait;

public class MyThread extends Thread {
    private String a = "a";

    public MyThread(String a) {
        this.a = a;
    }

    @Override
    public void run() {
        synchronized (a){
            System.out.println("开始Wait --time:" + System.currentTimeMillis());
            try {
                a.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("结束wait -- time:" + System.currentTimeMillis());

        }
    }

    class MyThread1 extends Thread {
        private String a = "a";

        public MyThread1(String a) {
            this.a = a;
        }

        @Override
        public void run() {
            synchronized (a) {
                System.out.println("开始notify --time:" + System.currentTimeMillis());
                a.notify();
                System.out.println("结束notify -- time:" + System.currentTimeMillis());

            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        String b = "b";
        System.out.println("main函数 执行时间:"+ System.currentTimeMillis());
        MyThread a = new MyThread(b);
        a.start();
        Thread.sleep(3000);
        MyThread1 a1 = a.new MyThread1(b);
        a1.start();
        System.out.println("main 函数执行结束");
    }

}
